package demo.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class MessageProvider {

    private static final String DELAY_CHECK_TIME = String.valueOf(5*1000);

    @Resource
    RabbitTemplate rabbitTemplate;

    public void send(String msg) {
        rabbitTemplate.convertAndSend(ExchangeAndQueueConfig.RECORD_EXCHANGE, ExchangeAndQueueConfig.RECORD_CHECK_KEY,msg, message -> {
            MessageProperties messageProperties = message.getMessageProperties();
            messageProperties.setContentType("utf-8");
            //毫秒值
            messageProperties.setExpiration(DELAY_CHECK_TIME);
            return message;
        });
        log.info("消息发送内容:{}",msg);
    }
}
